using Nop.Core;
using Nop.Data;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;

namespace Nop.Plugin.ActiveForever.ActiveChat.Data
{
	public class ActiveChatObjectContext : DbContext, IDbContext
	{
		public ActiveChatObjectContext(string nameOrConnectionString) : base(nameOrConnectionString)
		{
		}

		public string CreateDatabaseInstallationScript()
		{
            return ((IObjectContextAdapter)this).ObjectContext.CreateDatabaseScript();
        }

		public int ExecuteSqlCommand(string sql, int? timeout = null, params object[] parameters)
		{
			throw new NotImplementedException();
		}

		public IList<TEntity> ExecuteStoredProcedureList<TEntity>(string commandText, params object[] parameters)
		where TEntity : BaseEntity, new()
		{
			throw new NotImplementedException();
		}

		public void Install()
		{
			Database.ExecuteSqlCommand(CreateDatabaseInstallationScript(), new object[0]);
			SaveChanges();
		}

		protected override void OnModelCreating(DbModelBuilder modelBuilder)
		{
			modelBuilder.Configurations.Add(new ClientChatLogMap());
			modelBuilder.Configurations.Add(new BannedClientMap());
			modelBuilder.Configurations.Add(new CannedResponseMap());
			base.OnModelCreating(modelBuilder);
		}

		public IDbSet<TEntity> Set<TEntity>()
		where TEntity : BaseEntity
		{
			return base.Set<TEntity>();
		}

		public IEnumerable<TElement> SqlQuery<TElement>(string sql, params object[] parameters)
		{
			throw new NotImplementedException();
		}

	    public int ExecuteSqlCommand(string sql, bool doNotEnsureTransaction = false, int? timeout = null, params object[] parameters)
	    {
	        throw new NotImplementedException();
	    }

	    public void Uninstall()
		{
			string[] newLine = { "DROP TABLE ActiveChat_ClientChatLog", Environment.NewLine, "DROP TABLE ActiveChat_BannedClients", Environment.NewLine, "DROP TABLE ActiveChat_CannedResponses" };
			string str = string.Concat(newLine);
			Database.ExecuteSqlCommand(str, new object[0]);
			SaveChanges();
		}
	}
}